package com.ruoyi.Unit.service.impl;

import java.util.List;

import com.ruoyi.Goover.domain.StudyEnglish;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.Unit.mapper.StudyUnitMapper;
import com.ruoyi.Unit.domain.StudyUnit;
import com.ruoyi.Unit.service.IStudyUnitService;

/**
 * 存储单元Service业务层处理
 * 
 * @author luobom
 * @date 2021-12-03
 */
@Service
public class StudyUnitServiceImpl implements IStudyUnitService 
{
    @Autowired
    private StudyUnitMapper studyUnitMapper;

    /**
     * 查询存储单元
     * 
     * @param uid 存储单元主键
     * @return 存储单元
     */
    @Override
    public StudyUnit selectStudyUnitByUid(String uid)
    {
        //过滤其它用户的值 改xml文件实在太麻烦了
        StudyUnit stu=studyUnitMapper.selectStudyUnitByUid(uid);
        if(stu!=null) {
            if(!stu.getCreateBy().equals(String.valueOf(SecurityUtils.getUserId()))){
                stu=null;
            }
        }
        return stu;
    }

    /**
     * 查询存储单元列表
     * 
     * @param studyUnit 存储单元
     * @return 存储单元
     */
    @Override
    public List<StudyUnit> selectStudyUnitList(StudyUnit studyUnit)
    {

        studyUnit.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return studyUnitMapper.selectStudyUnitList(studyUnit);
    }

    /**
     * 新增存储单元
     * 
     * @param studyUnit 存储单元
     * @return 结果
     */
    @Override
    public int insertStudyUnit(StudyUnit studyUnit)
    {
        studyUnit.setCreateTime(DateUtils.getNowDate());
        studyUnit.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return studyUnitMapper.insertStudyUnit(studyUnit);
    }

    /**
     * 修改存储单元
     * 
     * @param studyUnit 存储单元
     * @return 结果
     */
    @Override
    public int updateStudyUnit(StudyUnit studyUnit)
    {
        studyUnit.setUpdateTime(DateUtils.getNowDate());
        return studyUnitMapper.updateStudyUnit(studyUnit);
    }

    /**
     * 批量删除存储单元
     * 
     * @param uids 需要删除的存储单元主键
     * @return 结果
     */
    @Override
    public int deleteStudyUnitByUids(String[] uids)
    {
        return studyUnitMapper.deleteStudyUnitByUids(uids);
    }

    /**
     * 删除存储单元信息
     * 
     * @param uid 存储单元主键
     * @return 结果
     */
    @Override
    public int deleteStudyUnitByUid(String uid)
    {
        return studyUnitMapper.deleteStudyUnitByUid(uid);
    }
}
